package com.xsz.service;

import com.xsz.entity.Resume;
import com.xsz.entity.User;
import com.xsz.repository.ResumeRepository;
import com.xsz.util.KeyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ResumeService {
    @Resource
    ResumeRepository resumeRepository;

    /**查询当前用户简历**/
    public List<Resume> showById(String id) {
//        Sort sort = new Sort(Sort.Direction.DESC, "id");
//        Pageable pageable = PageRequest.of(Integer.parseInt(pageNum), Integer.parseInt(limitNum));

        return resumeRepository.findByCreateByOrderByCreateTimeDesc(id);
    }

    /**添加简历**/
    public Resume addResume(Resume resume, User user) {

        resume.setId(KeyUtil.getId());
        resume.setCreateBy(user.getId());

        return resumeRepository.save(resume);
    }


    /**添加简历**/
    public Resume addResume(Resume resume) {


        return resumeRepository.save(resume);
    }

    /**修改简历**/
    public Resume editResume(Resume resume) {
        return resumeRepository.save(resume);
    }

    /**删除简历**/
    public void deleteResume(String id) {
        resumeRepository.deleteById(id);
    }


    //按照用户id查询简历

    public List<Resume> selectById(String uid) {
        return resumeRepository.findByCreateByOrderByCreateTimeDesc(uid);
    }


    //按照简历id查询简历

    public Resume selectByResumeId(String id) {
        return resumeRepository.findById(id).get();
    }
}
